/*-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License.You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
	
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
	
The Original Code is Fever RS ( ActionScript 3 ) Framework code.
	
The Initial Developer of the Original Code is Romain Ecarnot.
Portions created by Initial Developer are Copyright (C) 2006
the Initial Developer. All Rights Reserved.
	
Contributor(s):
	
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-----------------------------------------------------------------------------*/

package fever.app.context.swfs 
{
	import flash.display.StageDisplayState;
	import flash.system.fscommand;
	
	import com.bourre.structures.Point;
	import com.bourre.structures.Rectangle;
	
	import fever.app.context.ApplicationContainer;
	import fever.app.context.abstract.AbstractContainer;
	import fever.core.RSCore;
	
	/**
	 * <strong>Nortcode SWF Studio</strong> container strategy.
	 * 
	 * TODO Not yet implemented
	 * 
	 * @includeExample StudioContainerSample.as -noswf
	 * 
	 * @see fever.app.context.ApplicationContainer
	 * @see fever.core.FeverCore
	 * 
	 * @author Romain Ecarnot
	 */
	public class StudioContainer extends AbstractContainer 
		implements ApplicationContainer 
	{
		//--------------------------------------------------------------------
		// Private properties
		//--------------------------------------------------------------------

		private var _sStoredTitle : String;		private var _bDisplayState : Boolean;

		
		//--------------------------------------------------------------------
		// Public API
		//--------------------------------------------------------------------
		
		/**
		 * @private
		 * Constructor.
		 */
		public function StudioContainer()
		{
			super( getConstructorAccess() );
			
			_bDisplayState = false;
		}
		
		/** 
		 * @inheritDoc
		 */
		public function setTitle( mainTitle : String = null, 
			subTitle : String = null, historyCaption : String = null ) : void
		{
			_sStoredTitle = getFullFormattedTitle( mainTitle, subTitle, historyCaption );
			ssCore.Win.setCaption( { text : _sStoredTitle } );
		}

		/** 
		 * @inheritDoc
		 */
		public function getTitle() : String
		{
			return _sStoredTitle;
		}

		/** 
		 * @inheritDoc
		 */
		public function move( x : int, y : int ) : void
		{
			if( !isFullScreen( ) )
			{
				ssCore.Win.setPosition( { x:x, y:y} );
			}
		}
		
		/** 
		 * @inheritDoc
		 */
		public function getLocation() : Point
		{
			var po : Object = ssCore.Win.getPosition( );
			
			return new Point( po.x, po.y );
		}

		/** 
		 * @inheritDoc
		 */
		public function setSize( width : int, height : int ) : void
		{
			if( !isFullScreen( ) )
			{
				ssCore.Win.setSize( {width:width, height:height} );
			}
		}

		/** 
		 * @inheritDoc
		 */
		public function getSize() : Rectangle
		{
			var so : Object = ssCore.Win.getSize( );
			var po : Object = ssCore.Win.getPosition( );
			
			return new Rectangle( so.width, so.width, po.x, po.y );
		}

		/** 
		 * @inheritDoc
		 */
		public function setFullScreenMode( b : Boolean ) : void
		{
			if( _bDisplayState != b )
			{
				fscommand( 'Fullscreen', ( b ) ? 'true' : 'false' );
				_bDisplayState = b;
			
				RSCore.stage.displayState = ( b ) ? StageDisplayState.FULL_SCREEN : StageDisplayState.NORMAL;
			}
			
			//TODO disptach FullScreenEvent.FULL_SCREEN
		}

		/** 
		 * @inheritDoc
		 */
		public function isFullScreen() : Boolean
		{
			return RSCore.stage.displayState == StageDisplayState.FULL_SCREEN;
		}

		/**
		 * Not available in Browser context.
		 * @inheritDoc
		 */
		public function maximize() : void
		{
			ssCore.Win.maximize( );
		}

		/**
		 * Not available in Browser context.
		 * @inheritDoc
		 */
		public function minimize() : void
		{
			ssCore.Win.minimize( );
		}

		/**
		 * Not available in Browser context.
		 * @inheritDoc
		 */
		public function restore() : void
		{
			ssCore.Win.restore( );
		}
		
		/** 
		 * @inheritDoc
		 */
		public function getArgument( id : String ) : String
		{
			var return_obj : Object = ssCore.App.getCommandLine();
			ssDebug.trace( return_obj.result );
						
			return "";
		}
	}
}
